#ifndef _HEALTH_STORAGE_H
#define _HEALTH_STORAGE_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/*
    数据格式：
    storage -- block 0
                -- record 0
                -- record 1
                -- ...
            -- block 1
                -- record 0
                -- record 1
                -- ...
            -- ...
    

    


 */

// 心率数据
#define HEART_DATA_NUM_PER_DAY (24 * 12)
#define HEART_DATA_STORAGE_SIZE 4096 // 总存储空间
#define HEART_DATA_BLOCK_NUM 2
#define HEART_DATA_BLOCK_SIZE (HEART_DATA_STORAGE_SIZE / HEART_DATA_BLOCK_NUM)
#define HEART_DATA_RECORD_SIZE 512                                             // 一条心率数据记录最大字节
#define HEART_DATA_RECORD_NUM (HEART_DATA_BLOCK_SIZE / HEART_DATA_RECORD_SIZE) // 心率数据记录最大条数

    // 一天的自动检测心率数据，5分钟一次，需求要求存3天，
    // 但flash空间充足，存8天再删除，保护flash擦写寿命
    typedef struct
    {
        uint32_t timestamp;
        uint8_t data[HEART_DATA_NUM_PER_DAY];
    } health_data_heart_t;

    // 用户发起的血压测量数据
    typedef struct
    {
        uint32_t timestamp;
        uint8_t sbp;
        uint8_t dbp;
        uint8_t reserve[2];
    } health_data_bp_t;

    void health_storage_init(void);
    void health_storage_exec(void);
    void health_storage_init_pstorage(void);
    void health_storage_reset_pstorage(void);
    int health_storage_add_heart_data(uint32_t timestamp, uint8_t heart_rate);
    void health_storage_add_heart_data_ext(uint8_t heart_rate);
    int health_storage_get_heart_data(uint32_t timestamp, health_data_heart_t *p_heart_data);

    int health_storage_get_last_data(uint8_t *p_data, int minute);
#ifdef __cplusplus
}
#endif

#endif
